package cn.blogsx.array;

/**
 * 简单数组算法
 */
public class Demo10ArrayAlgorithm {
    public static void main(String[] args) {
        //求数组arrayA中的最大值
        int [] arrayA = {1,3,2,4,5,19,500,39,230,239};
        System.out.println("最大值："+arrayMax(arrayA));

        //讲数组arrayA翻转：
        arrayReverse(arrayA);

    }
    public static int arrayMax(int [] array){


        int max=array[0];
        for (int i = 1; i < array.length; i++) {
            if(array[i]>max){
                max=array[i];
            }
        }

        return max;

    }

    /**
     * 数组翻转方法
     * @param array
     * @return
     */
    public static int[] arrayReverse(int [] array){
        System.out.println("翻转前遍历：");
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
        int temp=0;
        for (int i=0;i<array.length/2;i++){
            temp=array[i];
            array[i]=array[array.length-1-i];
            array[array.length-1-i]=temp;
        }
        System.out.println("翻转后：");
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        return array;
    }

}
